<%-- 
    Document   : registration_db
    Created on : 22 May, 2012, 4:11:44 PM
    Author     : bharat
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.sql.*" %>
<%
    Connection con = null;
    PreparedStatement pstmt = null;
    try {

        Class.forName("oracle.jdbc.driver.OracleDriver");
        con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "aksh", "aksh");

        String id = request.getParameter("id");
        String email = request.getParameter("email");
        pstmt = con.prepareCall("insert into valid_users_db values(?,?)");
        pstmt.setString(1, id);
        pstmt.setString(2, email);
        pstmt.executeUpdate();
        out.println(id + " with email id " + email + " is registered successfully.");
    } catch (Exception e) {
        out.println("Registration failed" + e.getMessage());
        e.printStackTrace();
    }
finally {
        if (con != null) {
            try {
                con.close();
            } catch (Exception e) {
                out.println("Connection cannot be closed");
                e.printStackTrace();
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (Exception e) {
                out.println("Prepared Statement cannot be closed");
                e.printStackTrace();
            }
        }
    }
%>